//
//  HoroscopeInfoViewController.m
//  HoroscopeApp
//
//  Created by qinjiandong on 2018/7/12.
//  Copyright © 2018年 qinjiandong. All rights reserved.
//

#import "HoroscopeInfoViewController.h"
#import "HoroscopeListViewController.h"
#import "LZPickerView.h"
#import "Util.h"

#define HoroArray  @[@"Aquarius", \
@"Pisces", \
@"Aries", \
@"Taurus", \
@"Gemini", \
@"Cancer", \
@"Leo", \
@"Virgo", \
@"Libra", \
@"Scorpio", \
@"Sagittarius", \
@"Capricornus" \
]

@interface HoroscopeInfoViewController ()
@property(nonatomic,strong)LZPickerView *lzPickerVIew;
@property (nonatomic,strong)NSArray *dataSorce;
@property (nonatomic,strong)NSArray *signDataSorce;
@property (nonatomic,strong)NSArray *genderDataSorce;
@property (nonatomic,strong)NSArray *regionDataSorce;

@property (nonatomic,copy)NSString *signInfo;
@property (nonatomic,copy)NSString *genderInfo;
@property (nonatomic,copy)NSString *regionInfo;
@property (nonatomic,assign)NSInteger selectedStyle;
@end

/*
 imageButton 111110 - 111117
 pointButton 222220 - 222227
 */
@implementation HoroscopeInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"iHoroscope";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:1.0 green:124.0/255.0 blue:119.0/255.0 alpha:1];

    self.selectedStyle = 0;
    self.signInfo  = @"Aquarius";
    self.genderInfo = @"Female";
    self.regionInfo = @"USA";
    self.signDataSorce = HoroArray;
    
    self.genderDataSorce = @[@"Female",@"Male"];
    self.regionDataSorce = @[@"USA",@"Canada",@"UK",@"Australia",@"Asia",@"Europe",@"Central America",@"South America",@"Africa"];
    NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"LZPickerView" owner:nil options:nil];
    self.lzPickerVIew  = views[0];
    
}

- (IBAction)selectSignActionn:(UIButton *)sender {
    
    [self showPickerViewWithDataSource:self.signDataSorce tag:200001];
  

}
- (IBAction)selectGenderAction:(UIButton *)sender {
    
    [self showPickerViewWithDataSource:self.genderDataSorce tag:200002];

    
}
- (IBAction)selectRegionAction:(UIButton *)sender {
    
    [self showPickerViewWithDataSource:self.regionDataSorce tag:200003];

}
- (void)showPickerViewWithDataSource:(NSArray *)dataSource tag:(NSInteger)tag{
    [self.lzPickerVIew lzPickerVIewType:LZPickerViewTypeSexAndHeight];
    self.lzPickerVIew.dataSource = dataSource;
    UIButton *signBtn = [self.view viewWithTag:tag];
    HoroscopeInfoViewController *weakSelf = self;
    self.lzPickerVIew.selectValue  = ^(NSString *value){
        [signBtn setTitle:value forState:UIControlStateNormal];
        switch (tag) {
            case 200001:
                weakSelf.signInfo = value;
                break;
            case 200002:
                weakSelf.genderInfo = value;
                break;
            case 200003:
                weakSelf.regionInfo = value;
                break;
            default:
                break;
        }
    };
    [self.lzPickerVIew show];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 3) {
        return ([UIScreen mainScreen].bounds.size.width/4 - 23)*3/2+56+20;
    }
    return 80;
}

- (IBAction)saveUserInfoAction:(UIButton *)sender {
    
    NSDictionary *infoDict = @{@"siginInfo":self.signInfo,@"genderInfo":self.genderInfo,@"regionInfo":self.regionInfo,@"selectedStyle":[NSNumber numberWithInteger:self.selectedStyle]};
    [[NSUserDefaults standardUserDefaults]setObject:infoDict forKey:@"userDefaults"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    [self performSegueWithIdentifier:@"HoroscopeDetailInfoController" sender:self];

}

- (IBAction)didSelectSignStyleAction:(UIButton *)sender {
    
    NSInteger styleInt = sender.tag%10;
    if (styleInt == self.selectedStyle) {
        return;
    }
    UIButton *selectedButton = [self.view viewWithTag:(222220+styleInt)];
    selectedButton.selected = YES;
    UIButton *preSelectedBtn = [self.view viewWithTag:(222220+self.selectedStyle)];
    [preSelectedBtn setSelected:NO];;
    self.selectedStyle = styleInt;
    
}

- (IBAction)gotoSignListAction:(UIBarButtonItem *)sender {
    
    NSDictionary *infoDict = @{@"siginInfo":self.signInfo,@"genderInfo":self.genderInfo,@"regionInfo":self.regionInfo,@"selectedStyle":[NSNumber numberWithInteger:self.selectedStyle]};
    [[NSUserDefaults standardUserDefaults]setObject:infoDict forKey:@"userDefaults"];
    [[NSUserDefaults standardUserDefaults]synchronize];
    [self performSegueWithIdentifier:@"HoroscopeListViewController" sender:self];
    
}

@end
